<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <script type="text/javascript" src="./script/rem.js"></script>
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta content="yes" name="apple-touch-fullscreen">
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="./css/font-awesome.css" />
    <link rel="stylesheet" type="text/css" href="./css/style.css" />
    <script type="text/javascript" src="./script/aui-slide.js"></script>
    <script type="text/javascript" src="./script/jquery.min.js"></script>
    <script type="text/javascript" src="./script/doT.min.js"></script>
    <script type="text/javascript" src="./script/base.js"></script>
    <script type="text/javascript" src="./script/api.js"></script></head>
    <script type="text/javascript" src="./script/aui-tab.js" ></script>
    <script type="text/javascript" src="./script/jquery-3.2.0.js"></script>
</head>
<body>

    <header class="head" style="padding-top:0.4rem;">
        <div class="head-l" tapmode onclick="closeWin()"><i class="fa fa-angle-left"></i></div>
        <h3>注册</h3>
        <div class="head-r"></div>
    </header>
    <div class="head-d" style="padding-top:0.4rem;"></div>
    <ul class="list-input mt20">
        <li>
            <label><i>*</i>真实姓名:</label>
            <input type="text" placeholder="请输入真实姓名" id="username">
        </li>
        <li>
            <label><i>*</i>支付宝号:</label>
            <input type="text" placeholder="提现时使用，请认真填写" id="alipay">
        </li>
        <li>
            <label><i>*</i>微信号:</label>
            <input type="text" placeholder="微信号" id="wechat">
        </li>
    </ul>
    <div class="btn-1 mt100 mb30" onclick="register();">提交注册</div>


</body>
<script type="text/javascript" src="./script/api.js"></script>
<script type="text/javascript" src="./script/index.js"></script>
<script type="text/javascript">

    apiready = function(){
        invite_code = api.pageParam.invite_code; // 邀请码
        sms_code = api.pageParam.sms_code; // 验证码
        mobile = api.pageParam.mobile; // 手机号
        password = api.pageParam.password; // 密码
    }

    // 注册
    function register(){

        var name = $api.byId('username').value;
        var alipay = $api.byId('alipay').value;
        var wechat = $api.byId('wechat').value;
        var registrationId = $api.getStorage('registrationId');

        if (!name) {
            api.toast({
                msg: '请输入真实姓名!',
                duration: 2000,
                location: 'bottom'
            });
            return false;
        }
        if (!alipay) {
            api.toast({
                msg: '请输入支付宝账号!',
                duration: 2000,
                location: 'bottom'
            });
            return false;
        }
        if (!wechat) {
            api.toast({
                msg: '请输入微信账号!',
                duration: 2000,
                location: 'bottom'
            });
            return false;
        }

        api.ajax({
            url: webAddress + '/api/auth/register',
            method: 'post',
            data: {
                values: {
                    name: name,
                    email: mobile,
                    password: password,
                    invite_code: invite_code,
                    sms_code: sms_code,
                    wechat: wechat,
                    alipay: alipay,
                    push_id: registrationId,
                },
            }
        },function(ret, err){
            if (ret) {
                // alert( JSON.stringify( ret ) );
                $api.setStorage('token', ret.token);
                $api.setStorage('game_userid', ret.id);

                // api.toast({
                //     msg: '注册成功!',
                //     duration: 2000,
                //     location: 'bottom',
                //     global: true,
                // });
                var setSele = 'registerGotoIndex();';
                api.execScript({
                    name: 'root',
                    script: setSele,
                });

            } else {
                // alert( JSON.stringify( err ) );
                if(err.statusCode == 400){
                    api.toast({
                        msg: err.body.message,
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            }
        });
    }

    function closeWin(){
        api.closeWin({
        });
    }
</script>
</html>
